/*
 * Human.fx
 *
 * Created on 06.11.2009, 20:23:10
 */

package javafx179labs.nez.lab4;

import javafx.scene.CustomNode;
import javafx.scene.Node;
import javafx.scene.Group;
import javafx.scene.shape.Ellipse;
import javafx.scene.paint.Color;
import javafx.scene.shape.Line;
import javafx.animation.Timeline;
import javafx.animation.KeyFrame;

/**
 * @author civil
 */

public class Human extends CustomNode {
    public var x: Float;
    public var y: Float;
    var c: Float = 10;

    var tm: Timeline = Timeline {
        autoReverse: true
        repeatCount: Timeline.INDEFINITE
        keyFrames: [
                KeyFrame {
                    time: 2s
                    values: [c => 20]
                }
        ]
    }



    public function animation(): Void {
        tm.play();
    }

    override public function create(): Node {
        def heightT = 150;
        def heightL = 50;
        def width = 25;
        var head: Ellipse = Ellipse {
            centerX: bind x
            centerY: bind y - heightT
            radiusX: 20
            radiusY: 30
            stroke: Color.BLACK
            fill: Color.WHITE
            onMouseClicked: onMouseClicked
        }

        var body: Group = Group {
            content: [
                    Line { //body
                        startX: bind x
                        endX: bind x
                        startY: bind head.centerY + head.radiusY
                        endY: bind y - heightL
                    }
                    Line { //right hand
                        startX: bind x
                        endX: bind x + c
                        startY: bind head.centerY + head.radiusY + 10
                        endY: bind head.centerY + head.radiusY + 30
                    }
                    Line { //left hand
                        startX: bind x
                        endX: bind x - c
                        startY: bind head.centerY + head.radiusY + 10
                        endY: bind head.centerY + head.radiusY + 30
                    }
                    Line {
                        startX: bind x
                        endX: bind x + c
                        startY: bind y - heightL
                        endY: bind y
                    }
                    Line {
                        startX: bind x
                        endX: bind x - c
                        startY: bind y - heightL
                        endY: bind y
                    }
            ]
        }

        Group {
            content: bind [head, body]
        }
    }
}
